package visualizer;

import java.util.LinkedHashMap;

import processing.core.PVector;
import visualizer.controller.GlobalAnalyzeExecutor;
import visualizer.controller.InputController;
import visualizer.data.DataSource;
import visualizer.drawable.Drawable;
import visualizer.drawable.DrawableSwitcher;
import visualizer.drawable.TransitioningDrawableSwitcher;
import visualizer.drawable.concrete.LoadingScreen;
import visualizer.drawable.transition.HorizontalScrollTransitionFactory;
import visualizer.google.GoogleServiceFactory;
import visualizer.google.IpAddressRetriever;
import visualizer.google.concrete.GlobalAnalyzer;
import visualizer.input.concrete.CountryComponent;
import visualizer.input.concrete.HeaderComponent;

/**
 * Sets up the core applet. Adds all Drawable and InputListener objects to the
 * applet.
 */
public class Bootstrap {
	
	private HeaderComponent headerComponent;
	private CountryComponent countryComponent;
	private LoadingScreen loading;
	private DrawableSwitcher<String> viewSwitcher;
	private InputController input = new InputController();
	
	public void init(App a) {
		a.size(1100, 800);
		a.noSmooth();
		
		headerComponent = new HeaderComponent(a, input);
		headerComponent.setFocus(true);
		
		a.add(headerComponent);

		countryComponent = new CountryComponent(
			new PVector(70, headerComponent.getSize().y),
			a.loadImage("images/world.png"),
			new PVector(0, 0),
			input.getCountryColors()
		);
		
		a.addListener(countryComponent);
		
		loading = new LoadingScreen(a.loadImage("images/arrow.png"));
		
		viewSwitcher = new DrawableSwitcher<String>(new LinkedHashMap<String, Drawable>() {{
			put("countries", countryComponent);
			put("loading", loading);
		}});
		
		a.addDrawable(viewSwitcher);
		
		GoogleServiceFactory services = new GoogleServiceFactory(new IpAddressRetriever(a)); 
		GlobalAnalyzeExecutor gae = new GlobalAnalyzeExecutor(new GlobalAnalyzer(services.create()), a);
		gae.attach(input, viewSwitcher);
	}
}
